<!doctype html><html lang=en>
 <head>
  <meta content="text/html;charset=UTF-8" http-equiv=Content-type>
  <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
  <title>Media Queries Level 3</title>
  <meta content="ED" name="w3c-status">
  <link href="../default.css" rel=stylesheet>
  <!-- <link href="default.css" rel=stylesheet> -->

  <link href="https://www.w3.org/2008/site/images/favicon.ico" rel="icon">
  <link href="https://drafts.csswg.org/csslogo.ico" rel="icon">
  <link rel="canonical" href="https://www.w3.org/TR/mediaqueries-3/">
<style>/* style-counters */

body {
    counter-reset: example figure issue;
}
.issue {
    counter-increment: issue;
}
.issue:not(.no-marker)::before {
    content: "Issue " counter(issue);
}

.example {
    counter-increment: example;
}
.example:not(.no-marker)::before {
    content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
    content: "Invalid Example" counter(example);
}

figcaption {
    counter-increment: figure;
}
figcaption:not(.no-marker)::before {
    content: "Figure " counter(figure) " ";
}</style>
<link href="https://www.w3.org/StyleSheets/TR/2021/W3C-ED" rel=stylesheet>

 <body>
  <div class=head>
   <p><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2021/logos/W3C" width="72"> </a> </p>

   <h1 id=title>Media Queries Level 3</h1>

   <!-- <p id="w3c-state"><a href="https://www.w3.org/standards/types#REC">W3C Recommendation</a>, <time class="dt-updated" datetime="2024-05-14">14 May 2024</time></p> -->
   <p id="w3c-state"><a href="https://www.w3.org/standards/types#ED">Editor’s Draft</a>, <time class="dt-updated" datetime="2024-05-01">14 May 2024</time></p>

   <details open><summary>More details about this document</summary>
   <dl>
    <dt>This Version:

    <dd><a
     href="https://drafts.csswg.org/css3-mediaqueries/">https://drafts.csswg.org/mediaqueries-3/</a>
     <!-- <dd><a
      href="https://www.w3.org/TR/2022/REC-mediaqueries-3-20220405/">https://www.w3.org/TR/2022/REC-mediaqueries-3-20220405/</a> -->

    <dt>Latest Version:

    <dd><a
     href="https://www.w3.org/TR/mediaqueries-3/">https://www.w3.org/TR/mediaqueries-3/</a>

    <dt>Latest Editor Version:

    <dd><a
     href="https://drafts.csswg.org/mediaqueries-3/">https://drafts.csswg.org/mediaqueries-3/</a>

    <dt>Previous Version:

    <dd><a
     href="https://www.w3.org/TR/2024/REC-mediaqueries-3-20240521/">https://www.w3.org/TR/2024/REC-mediaqueries-3-20240521/</a>

    <dt>History:

    <dd><a href="https://www.w3.org/standards/history/mediaqueries-3"
      data-previous-shortname="css3-mediaqueries">https://www.w3.org/standards/history/mediaqueries-3</a>

    <dt>Disposition of Comments:

    <dd><a
     href="https://drafts.csswg.org/mediaqueries-3/issues-2012-and-later">https://drafts.csswg.org/mediaqueries-3/issues-2012-and-later</a>

    <dt>Implementation Report:

    <dd><a href="https://drafts.csswg.org/mediaqueries-3/impl-report">https://drafts.csswg.org/mediaqueries-3/impl-report</a></dd>

    <dt>Editors:

     <dd class="editor p-author h-card vcard" data-editor-id="43241"><a class="p-name fn u-url url" href="https://florian.rivoal.net">Florian Rivoal</a> (<span class="p-org org">Invited Expert</span>)

    <dt>Previous Editors:

    <dd class=vcard><a class="url fn n"
     href="http://people.opera.com/howcome/" lang=no> <span
     class=given-name>H&aring;kon</span> <span
     class=additional-name>Wium</span> <span class=family-name>Lie</span></a>
     &lt;<span class=email>howcome&nbsp;@opera.com</span>&gt;

    <dd class=vcard><a class="url fn" href="http://tantek.com/"
     lang=tr>Tantek &Ccedil;elik</a> &lt;<span
     class=email>tantek&nbsp;@cs.stanford.edu</span>&gt;

    <dd class=vcard><span class=given-name>Daniel</span> <span
     class=family-name>Glazman</span> &lt;<span
     class=email>daniel.glazman&nbsp;@disruptive-innovations.com</span>&gt;

    <dd class=vcard><a class="url fn n" href="http://annevankesteren.nl/"
     hreflang=en lang=nl>Anne van Kesteren</a> &lt;<span
     class=email>annevk@opera.com</span>&gt;

    <dt>Feedback:

    <dd><a href="https://github.com/w3c/csswg-drafts/issues">GitHub
      Issues</a> are preferred for discussion of this specification. When
      filing an issue, please put the text “mediaqueries-3” in the title,
      preferably like this: “[mediaqueries-3] <i>…summary of
      comment…</i>”. All issues and comments are <a href="https://lists.w3.org/Archives/Public/public-css-archive/">archived</a>,
      and there is also a <a href="https://lists.w3.org/Archives/Public/www-style/">historical
      archive</a>.

    <dt>Errata:
    <dd><a href="http://www.w3.org/Style/2022/REC-mediaqueries-3-20220405-errata.html">http://www.w3.org/Style/2022/REC-mediaqueries-3-20220405-errata.html</a>
   </dl>
   </details>

    <!-- <p>Please refer to the <a href="http://www.w3.org/Style/2022/REC-mediaqueries-3-20220405-errata.html"><strong>errata</strong></a> for this document, which may include some normative corrections.</p> -->

   <!-- <p>See also <a href="http://www.w3.org/2003/03/Translations/byTechnology?technology=css3-mediaqueries"> <strong>translations</strong></a>.</p> -->

   <!--begin-copyright-->
   <p class="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2022 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="https://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/copyright-software">permissive document license</a> rules apply.</p>
   <!--end-copyright-->
   <hr title="Separator for header">
  </div>

  <h2 class="no-num no-toc" id=abstract>Abstract</h2>

  <p>HTML4 and CSS2 currently support media-dependent style sheets tailored
   for different <em>media types</em>. For example, a document may use
   sans-serif fonts when displayed on a screen and serif fonts when printed.
   &lsquo;<code class=css>screen</code>&rsquo; and &lsquo;<code
   class=css>print</code>&rsquo; are two media types that have been defined.
   <em>Media queries</em> extend the functionality of media types by allowing
   more precise labeling of style sheets.

  <p>A media query consists of a media type and zero or more expressions that
   check for the conditions of particular <em>media features</em>. Among the
   media features that can be used in media queries are &lsquo;<code
   class=css>width</code>&rsquo;, &lsquo;<code
   class=css>height</code>&rsquo;, and &lsquo;<code
   class=css>color</code>&rsquo;. By using media queries, presentations can
   be tailored to a specific range of output devices without changing the
   content itself.

  <h2 class="no-num no-toc" id=status>Status of this Document</h2>
  <!--begin-status-->

  <!-- <p><em>This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the <a href="https://www.w3.org/TR/">W3C technical reports index</a> at https://www.w3.org/TR/.</em></p> -->

  <p>This is a public copy of the editors' draft. It is provided for
   discussion only and may change at any moment. Its publication here does
   not imply endorsement of its contents by W3C. Don't cite this document
   other than as work in progress.

  <!-- <p>This document was published by the
  <a href="https://www.w3.org/groups/wg/css">CSS Working Group</a>
  as a Recommendation using the
  <a href="https://www.w3.org/2023/Process-20231103/#recs-and-notes">Recommendation track</a>.
  It includes <a href="https://www.w3.org/2023/Process-20231103/#proposed-corrections">proposed corrections</a>.</p>

  <p>A W3C Recommendation is a specification that, after extensive consensus-building, is endorsed by <abbr title="World Wide Web Consortium">W3C</abbr> and its Members, and has commitments from Working Group members to <a href="https://www.w3.org/Consortium/Patent-Policy/#sec-Requirements">royalty-free licensing</a> for implementations.</p>

  <p>W3C recommends the wide deployment of this specification as a standard for the Web.</p> -->

  <p>Please send feedback
   by <a href="https://github.com/w3c/csswg-drafts/issues">filing issues in GitHub</a> (preferred),
   including the spec code “mediaqueries-3” in the title, like this:
   “[mediaqueries-3] <i>…summary of comment…</i>”.
   All issues and comments are <a href="https://lists.w3.org/Archives/Public/public-css-archive/">archived</a>.
   Alternately, feedback can be sent to the (<a href="https://lists.w3.org/Archives/Public/www-style/">archived</a>) public mailing list <a href="mailto:www-style@w3.org?Subject=%5Bmediaqueries-3%5D%20PUT%20SUBJECT%20HERE">www-style@w3.org</a>.
   Comments are due by 5 June 2022.

   <p>This document is governed by the <a href="https://www.w3.org/2023/Process-20231103/" id="w3c_process_revision">3 November 2023 W3C Process Document</a>.

  <p>This document was produced by a group operating under the <a
   href="https://www.w3.org/Consortium/Patent-Policy/">W3C Patent Policy</a>.
   W3C maintains a <a href="https://www.w3.org/groups/wg/css/ipr"
   rel=disclosure>public list of any patent disclosures</a> made in
   connection with the deliverables of the group; that page also includes
   instructions for disclosing a patent. An individual who has actual
   knowledge of a patent which the individual believes contains <a
   href="https://www.w3.org/Consortium/Patent-Policy/#def-essential">Essential
   Claim(s)</a> must disclose the information in accordance with <a
   href="https://www.w3.org/Consortium/Patent-Policy/#sec-Disclosure">section 6 of the
   W3C Patent Policy</a>.</p>
  <!--end-status-->

  <div class="correction proposed"><a href="https://www.w3.org/2021/Process-20211102/#proposed-corrections">Proposed corrections</a> are marked in the document.</div>

  <nav id="toc">
  <h2 class="no-num no-toc" id=contents>Table of contents</h2>
  <!--begin-toc-->

  <ul class=toc>
   <li><a href="#background"><span class=secno>1. </span>Background</a>

   <li><a href="#media0"><span class=secno>2. </span>Media Queries</a>

   <li><a href="#syntax"><span class=secno>3. </span>Syntax</a>
    <ul class=toc>
     <li><a href="#error-handling"><span class=secno>3.1. </span>Error
      Handling</a>
    </ul>

   <li><a href="#media1"><span class=secno>4. </span>Media features</a>
    <ul class=toc>
     <li><a href="#width"><span class=secno>4.1. </span>width</a>

     <li><a href="#height"><span class=secno>4.2. </span>height</a>

     <li><a href="#device-width"><span class=secno>4.3.
      </span>device-width</a>

     <li><a href="#device-height"><span class=secno>4.4.
      </span>device-height</a>

     <li><a href="#orientation"><span class=secno>4.5. </span>orientation</a>


     <li><a href="#aspect-ratio"><span class=secno>4.6.
      </span>aspect-ratio</a>

     <li><a href="#device-aspect-ratio"><span class=secno>4.7.
      </span>device-aspect-ratio</a>

     <li><a href="#color"><span class=secno>4.8. </span>color</a>

     <li><a href="#color-index"><span class=secno>4.9. </span>color-index</a>


     <li><a href="#monochrome"><span class=secno>4.10. </span>monochrome</a>

     <li><a href="#resolution"><span class=secno>4.11. </span>resolution</a>

     <li><a href="#scan"><span class=secno>4.12. </span>scan</a>

     <li><a href="#grid"><span class=secno>4.13. </span>grid</a>
    </ul>

   <li><a href="#values"><span class=secno>5. </span>Values</a>

   <li><a href="#units"><span class=secno>6. </span>Units</a>
    <ul class=toc>
     <li><a href="#resolution0"><span class=secno>6.1. </span>Resolution</a>
    </ul>

   <li><a href="#changes"><span class=secno>7. </span>Changes</a>
    <ul class=toc>
     <li><a href="#changes-2022"><span class=secno>7.1. </span>Changes Since
      the 05 April 2022 Recommendation</a>
     <li><a href="#changes-2012"><span class=secno>7.2. </span>Changes Since
      the 19 June 2012 Recommendation</a>
     <li><a href="#changes-2010"><span class=secno>7.3. </span>Changes Since
      the 27 July 2010 Candidate Recommendation</a>
    </ul>

   <li class=no-num><a href="#acknowledgments">Acknowledgments</a>

   <li class=no-num><a href="#references">References</a>
    <ul class=toc>
     <li class=no-num><a href="#normative-references">Normative
      references</a>

     <li class=no-num><a href="#other-references">Other references</a>
    </ul>
  </ul>
  <!--end-toc-->
  </nav>

  <h2 id=background><span class=secno>1. </span>Background</h2>

  <p>(This section is not normative.)

  <p>HTML4 <a href="#HTML401" rel=biblioentry>[HTML401]<!--{{HTML401}}--></a>
   and CSS2 <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>
   currently support media-dependent style sheets tailored for different
   media types. For example, a document may use different style sheets for
   screen and print. In HTML4, this can be written as:

  <div class=example>
   <pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="sans-serif.css">
&lt;link rel="stylesheet" type="text/css" media="print" href="serif.css"></code></pre>
  </div>

  <p>Inside a CSS style sheet, one can declare that sections apply to certain
   media types:

  <div class=example>
   <pre><code>@media screen {
  * { font-family: sans-serif }
}</code></pre>
  </div>

  <p>The &lsquo;<code class=css>print</code>&rsquo; and &lsquo;<code
   class=css>screen</code>&rsquo; media types are defined in HTML4. The
   complete list of media types in HTML4 is: &lsquo;<code
   class=css>aural</code>&rsquo;, &lsquo;<code
   class=css>braille</code>&rsquo;, &lsquo;<code
   class=css>handheld</code>&rsquo;, &lsquo;<code
   class=css>print</code>&rsquo;, &lsquo;<code
   class=css>projection</code>&rsquo;, &lsquo;<code
   class=css>screen</code>&rsquo;, &lsquo;<code class=css>tty</code>&rsquo;,
   &lsquo;<code class=css>tv</code>&rsquo;. CSS2 defines the same list,
   deprecates &lsquo;<code class=css>aural</code>&rsquo; and adds
   &lsquo;<code class=css>embossed</code>&rsquo; and &lsquo;<code
   class=css>speech</code>&rsquo;. Also, &lsquo;<code
   class=css>all</code>&rsquo; is used to indicate that the style sheet
   applies to all media types.

  <p>Media-specific style sheets are supported by several user agents. The
   most commonly used feature is to distinguish between &lsquo;<code
   class=css>screen</code>&rsquo; and &lsquo;<code
   class=css>print</code>&rsquo;.

  <p>There have been requests for ways to describe in more detail what type
   of output devices a style sheet applies to. Fortunately HTML4 foresaw
   these requests and defined a forward-compatible syntax for media types.
   Here is a quote from <a
   href="https://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13">HTML4,
   section 6.13</a>:

  <blockquote
   cite="http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13">
   <p>Future versions of HTML may introduce new values and may allow
    parameterized values. To facilitate the introduction of these extensions,
    conforming user agents must be able to parse the <a
    href="http://www.w3.org/TR/1999/REC-html401-19991224/present/styles.html#adef-media"><samp>media</samp></a>
    attribute value as follows:

   <ol>
    <li>The value is a comma-separated list of entries. For example,
     <pre><code>media="screen, 3d-glasses, print and resolution > 90dpi"</code></pre>

     <p>is mapped to:</p>

     <pre><code>"screen"
"3d-glasses"
"print and resolution > 90dpi"</code></pre>

    <li>Each entry is truncated just before the first character that isn't a
     US ASCII letter [a-zA-Z] (Unicode decimal 65-90, 97-122), digit [0-9]
     (Unicode hex 30-39), or hyphen (45). In the example, this gives:
     <pre><code>"screen"
"3d-glasses"
"print"</code></pre>
   </ol>
  </blockquote>

  <p>Media queries, as described in this specification, build on the
   mechanism outlined in HTML4. The syntax of media queries fit into the
   media type syntax reserved in HTML4. The <code class=html>media</code>
   attribute of HTML4 also exists in XHTML and generic XML. The same syntax
   can also be used inside in the &lsquo;<code class=css>@media</code>&rsquo;
   and &lsquo;<code class=css>@import</code>&rsquo; rules of CSS.

  <p>However, the parsing rules for media queries are incompatible with those
   of HTML4 so that they are consistent with those of media queries used in
   CSS.

  <p class=note>Newer versions of HTML <a href="#biblio-html"
   rel=biblioentry>[HTML]</a>
   reference the Media Queries specification
   directly and thus updates the rules for HTML.

  <h2 id=media0><span class=secno>2. </span>Media Queries</h2>

  <p>A media query consists of a media type and zero or more <span
   class=index id=expressions>expressions</span> that check for the
   conditions of particular <span class=index id=media-features>media
   features</span>.

  <p>Statements regarding media queries in this section assume the <a
   href="#syntax">syntax section</a> is followed. Media queries that do not
   conform to the syntax are discussed in the <a href="#error-handling">error
   handling section</a>. I.e. the syntax takes precedence over requirements
   in this section.

  <div class=example>
   <p>Here is a simple example written in HTML:</p>

   <pre><code>&lt;link rel="stylesheet" media="screen and (color)" href="example.css" /></code></pre>

   <p>This example expresses that a certain style sheet
    (<code>example.css</code>) applies to devices of a certain media type
    (&lsquo;<code class=css>screen</code>&rsquo;) with certain feature (it
    must be a color screen).</p>
  </div>

  <div class=example>
   <p>Here the same media query written in an @import-rule in CSS:</p>

   <pre><code>@import url(color.css) screen and (color);</code></pre>
  </div>

  <p>A media query is a logical expression that is either true or false. A
   media query is true if the media type of the media query matches the media
   type of the device where the user agent is running (as defined in the
   "Applies to" line), and all expressions in the media query are true.

  <p>A shorthand syntax is offered for media queries that apply to all media
   types; the keyword &lsquo;<code class=css>all</code>&rsquo; can be left
   out (along with the trailing &lsquo;<code class=css>and</code>&rsquo;).
   I.e. if the media type is not explicitly given it is &lsquo;<code
   class=css>all</code>&rsquo;.

  <div class=example>
   <p>I.e. these are identical:</p>

   <pre><code>@media all and (min-width:500px) { &hellip; }
@media (min-width:500px) { &hellip; }</code></pre>

   <p>As are these:</p>

   <pre><code>@media (orientation: portrait) { &hellip; }
@media all and (orientation: portrait) { &hellip; }</code></pre>
  </div>

  <p>Several media queries can be combined in a media query list. A
   comma-separated list of media queries. If one or more of the media queries
   in the comma-separated list are true, the whole list is true, and
   otherwise false. In the media queries syntax, the comma expresses a
   logical OR, while the &lsquo;<code class=css>and</code>&rsquo; keyword
   expresses a logical AND.

  <div class=example>
   <p>Here is an example of several media queries in a comma-separated list
    using the an @media-rule in CSS:</p>

   <pre><code>@media <em>screen and (color), projection and (color)</em> { &hellip; }</code></pre>
  </div>

  <p>If the media query list is empty (i.e. the declaration is the empty
   string or consists solely of whitespace) it evaluates to true.

  <div class=example>
   <p>I.e. these are equivalent:</p>

   <pre><code>@media all { &hellip; }
@media { &hellip; }</code></pre>
  </div>

  <p>The logical NOT can be expressed through the &lsquo;<code
   class=css>not</code>&rsquo; keyword. The presence of the keyword
   &lsquo;<code class=css>not</code>&rsquo; at the beginning of the media
   query negates the result. I.e., if the media query had been true without
   the &lsquo;<code class=css>not</code>&rsquo; keyword it will become false,
   and vice versa. User agents that only support media types (as described in
   HTML4) will not recognize the &lsquo;<code class=css>not</code>&rsquo;
   keyword and the associated style sheet is therefore not applied.

  <div class=example>
   <pre><code>&lt;link rel="stylesheet" media="<em>not screen and (color)</em>" href="example.css" /&gt;</code></pre>
  </div>

  <p>The keyword &lsquo;<code class=css>only</code>&rsquo; can also be used
   to hide style sheets from older user agents. User agents must process
   media queries starting with &lsquo;<code class=css>only</code>&rsquo; as
   if the &lsquo;<code class=css>only</code>&rsquo; keyword was not present.

  <div class=example>
   <pre><code>&lt;link rel="stylesheet" media="<em>only screen and (color)</em>" href="example.css" /&gt;</code></pre>
  </div>

  <p>The media queries syntax can be used with HTML, XHTML, XML <a
   href="#XMLSTYLE" rel=biblioentry>[XMLSTYLE]<!--{{XMLSTYLE}}--></a> and the
   @import and @media rules of CSS.

  <div class=example>
   <p>Here is the same example written in HTML, XHTML, XML, @import and
    @media:</p>

   <pre><code>&lt;link media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css"></code></pre>

   <pre><code>&lt;link media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" /></code></pre>

   <pre><code>&lt;?xml-stylesheet media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" ?></code></pre>

   <pre><code>@import url(example.css) <em>screen and (color), projection and (color)</em>;</code></pre>

   <pre><code>@media <em>screen and (color), projection and (color)</em> { &hellip; }</code></pre>

   <p class=note>The <a href="#XMLSTYLE"
    rel=biblioentry>[XMLSTYLE]<!--{{XMLSTYLE}}--></a> specification has not
    yet been updated to use media queries in the <code>media</code>
    pseudo-attribute.</p>
  </div>

  <p>If a media feature does not apply to the device where the UA is running,
   expressions involving the media feature will be false.

  <div class=example>
   <p>The media feature &lsquo;<code
    class=css>device-aspect-ratio</code>&rsquo; only applies to visual
    devices. On an aural device, expressions involving &lsquo;<code
    class=css>device-aspect-ratio</code>&rsquo; will therefore always be
    false:</p>

   <pre><code>&lt;link rel="stylesheet" media="aural and (device-aspect-ratio: 16/9)" href="example.css" /&gt;</code></pre>
  </div>

  <p>Expressions will always be false if the unit of measurement does not
   apply to the device.

  <div class=example>
   <p>The &lsquo;<code class=css>px</code>&rsquo; unit does not apply to
    &lsquo;<code class=css>speech</code>&rsquo; devices so the following
    media query is always false:</p>

   <pre><code>&lt;link rel="stylesheet" media="speech and (min-device-width: 800px)" href="example.css" /&gt;</code></pre>

   <p>Note that the media queries in this example would have been true if the
    keyword &lsquo;<code class=css>not</code>&rsquo; had been added to the
    beginning of the media query.</p>
  </div>

  <p>To avoid circular dependencies, unless another feature explicitly
   specifies that it affects the resolution of Media Queries, it is not necessary to apply the style
   sheet in order to evaluate expressions. For example, the aspect ratio of a
   printed document may be influenced by a style sheet, but expressions
   involving &lsquo;<code class=css>device-aspect-ratio</code>&rsquo; will be
   based on the default aspect ratio of the user agent.

  <p class=note>User agents are expected, but not required, to re-evaluate
   and re-layout the page in response to changes in the user environment, for
   example if the device is tilted from landscape to portrait mode.

  <h2 id=syntax><span class=secno>3. </span>Syntax</h2>

  <p>The media query syntax is described in terms of the <a
   href="https://www.w3.org/TR/CSS21/grammar.html">CSS2 grammar</a>. As such,
   rules not defined here are defined in CSS2. The
   <code>media_query_list</code> production defined below replaces the
   <code>media_list</code> production from CSS2. <a href="#CSS21"
   rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>

  <pre>media_query_list
 : S* [media_query [ ',' S* media_query ]* ]?
 ;
media_query
 : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
 | expression [ AND S* expression ]*
 ;
media_type
 : IDENT
 ;
expression
 : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
 ;
media_feature
 : IDENT
 ;</pre>

  <p>COMMENT tokens, as defined by CSS2, do not occur in the grammar (to keep
   it readable), but any number of these tokens may appear anywhere between
   other tokens. <a href="#CSS21"
   rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>

  <p>The following new definitions are introduced:

  <pre>L  l|\\0{0,4}(4c|6c)(\r\n|[ \t\r\n\f])?|\\l
Y  y|\\0{0,4}(59|79)(\r\n|[ \t\r\n\f])?|\\y</pre>

  <p>The following new tokens are introduced:

  <pre>{O}{N}{L}{Y}      {return ONLY;}
{N}{O}{T}         {return NOT;}
{A}{N}{D}         {return AND;}
{num}{D}{P}{I}    {return RESOLUTION;}
{num}{D}{P}{C}{M} {return RESOLUTION;}</pre>

  <p><code>RESOLUTION</code> is to be added to the CSS2 <code>term</code>
   production.

 <p>CSS style sheets are generally <a
   href="https://infra.spec.whatwg.org/#ascii-case-insensitive">ASCII
   case-insensitive</a>, and this is also the case for media queries.

  <p>In addition to conforming to the syntax, each media query needs to use
   media types and media features according to their respective specification
   in order to be considered conforming.

  <div class=example>
   <p>Only the first media query is conforming in the example below because
    the "example" media type does not exist.</p>

   <pre><code>@media all { body { background:lime } }
@media example { body { background:red } }</code></pre>
  </div>

  <h3 id=error-handling><span class=secno>3.1. </span>Error Handling</h3>

  <p>For media queries that are not conforming user agents need to follow the
   rules described in this section.

  <div class="correction proposed" id="c2">
   <span class="marker">Proposed Correction 2:</span>
   Require that ‘<code>layer</code>’ is also to not be treated as an unknown media type,
   but as a syntax errors when used in place of media types.

   <p>This change was introduced as a result of <a href="https://github.com/w3c/csswg-drafts/issues/7225">issue 7225</a>.

   <details>
    <summary>This change has tests</summary>
    <a href="https://github.com/web-platform-tests/wpt/pull/33940">Tests for this change</a> have been added to <abbr title="Web Platform Tests">WPT</abbr>.
    The results can be viewed at <a href="https://wpt.fyi/results/css/mediaqueries?q=mq-invalid-media-type-layer">wpt.fyi</a>.
   </details>

  </div>

  <ul>
   <li>
    <p><strong>Unknown media types.</strong> Unknown media types evaluate to
     false. Effectively, they are treated identically to known media types
     that do not match the media type of the device.
     However, an exception is made for media types <ins cite=#c2>‘<code>layer</code>’, </ins>‘<code>not</code>’, ‘<code>and</code>’, ‘<code>only</code>’, and ‘<code>or</code>’.
     Even though they do match the IDENT production,
     they must not be treated as unknown media types,
     but rather trigger the malformed query clause.</p>

     <ins cite=#c2>
     <p class=note>
     Note: The exclusion of ‘<code>layer</code>’ is because
     it would otherwise be ambiguous
     when used in the <code>@import url(…) layer;</code> syntax
     for the sake of <a href="https://www.w3.org/TR/css-cascade-5/#layering">cascade layers</a>.
     See <a href="biblio-css-cascade-5">[CSS-CASCADE-5]</a>.
     </p></ins>

    <div class=example>
     <p>The media query "<code>unknown</code>" will evaluate to false, unless
      <code>unknown</code> is actually a supported media type. Similarly,
      "<code>not unknown</code>" will evaluate to true.</p>
    </div>

    <div class="example">
     <p>The following is a malformed media query because it uses ‘<code>only</code>’ and ‘<code>or</code>’ as media types.</p>
     <pre><code>@media only and or { … }</code></pre>
    </div>

    <p class=note>Unknown media types are distinct from media types that do
     not actually match the IDENT production. Those fall under the malformed
     media query clause.</p>

   <li>
    <p><strong>Unknown media features.</strong> User agents are to represent
     a media query as "<code>not all</code>" when one of the specified media
     features is not known.</p>

    <div class=example>
     <pre><code>&lt;link rel="stylesheet" media="screen and (max-weight: 3kg) and (color), (color)" href="example.css" /&gt;</code></pre>

     <p>In this example, the first media query will be represented as
      "<code>not all</code>" and evaluate to false and the second media query
      is evaluated as if the first had not been specified, effectively.</p>
    </div>

    <div class=example>
     <pre><code>@media (min-orientation:portrait) { &hellip; }</code></pre>

     <p>Is represented as "<code>not all</code>" because the &lsquo;<code
      class=css>orientation</code>&rsquo; feature does not accept the
      &lsquo;<code class=css>min-</code>&rsquo; prefix.</p>
    </div>

   <li>
    <p><strong>Unknown media feature values.</strong> As with unknown media
     features, user agents are to represent a media query as "<code>not
     all</code>" when one of the specified media feature values is not known.</p>

    <div class=example>
     <p>The media query <code>(color:20example)</code> specifies an unknown
      value for the &lsquo;<code class=css>color</code>&rsquo; media feature
      and is therefore represented as "<code>not all</code>".</p>
    </div>

    <div class=example>
     <p>This media query is represented as "<code>not all</code>" because
      negative lengths are not allowed for the &lsquo;<code
      class=css>width</code>&rsquo; media feature:</p>

     <pre><code>@media (min-width: -100px) { &hellip; }</code></pre>
    </div>

   <li>
    <p><strong>Malformed media query.</strong> User agents are to handle
     unexpected tokens encountered while parsing a media query by reading
     until the end of the media query, while observing <a
     href="https://www.w3.org/TR/CSS21/syndata.html#block">the rules for
     matching pairs</a> of (), [], {}, "", and &#39;&#39;, and correctly
     handling escapes. Media queries with unexpected tokens are represented
     as "<code>not all</code>". <a href="#CSS21"
     rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>

    <div class=example>
     <pre><code>@media (example, all,), speech { /* only applicable to speech devices */ }
@media &amp;test, screen           { /* only applicable to screen devices */ }</code></pre>
    </div>

    <div class=example>
     <p>The following is an malformed media query because having no space
      between &lsquo;<code class=css>and</code>&rsquo; and the expression is
      not allowed. (That is reserved for the functional notation syntax.)</p>

     <pre><code>@media all and(color) { &hellip; }</code></pre>
    </div>

    <p>Media queries are expected to follow the error handling rules of the
     host language as well.</p>

    <div class=example>
     <pre><code>@media test;,all { body { background:lime } }</code></pre>

     <p>&hellip; will not apply because the semicolon terminates the
      <code>@media</code> rule in CSS.</p>
    </div>
  </ul>

  <h2 id=media1><span class=secno>4. </span>Media features</h2>

  <p>Syntactically, media features resemble CSS properties: they have names
   and accept certain values. There are, however, several important
   differences between properties and media features:

  <ul>
   <li>Properties are used in <em>declarations</em> to give information about
    how to present a document. Media features are used in
    <em>expressions</em> to describe requirements of the output device.

   <li>Most media features accept optional &lsquo;<code
    class=css>min-</code>&rsquo; or &lsquo;<code class=css>max-</code>&rsquo;
    prefixes to express "greater or equal to" and "smaller or equal to"
    constraints. This syntax is used to avoid "&lt;" and "&gt;" characters
    which may conflict with HTML and XML. Those media features that accept
    prefixes will most often be used with prefixes, but can also be used
    alone.

   <li>Properties always require a value to form a declaration. Media
    features, on the other hand, can also be used without a value. For a
    media feature <var>feature</var>, <code>(<var>feature</var>)</code> will
    evaluate to true if <code>(<var>feature</var>:<var>x</var>)</code> will
    evaluate to true for a value <var>x</var> other than zero or zero
    followed by a unit identifier (i.e., other than <code>0</code>,
    <code>0px</code>, <code>0em</code>, etc.). Media features that are
    prefixed by min/max cannot be used without a value. When a media feature
    prefixed with min/max is used without a value it makes the media query
    malformed.

   <li>Properties may accept more complex values, e.g., calculations that
    involve several other values. Media features only accept single values:
    one keyword, one number, or a number with a unit identifier. (The only
    exceptions are the &lsquo;<code class=css>aspect-ratio</code>&rsquo; and
    &lsquo;<code class=css>device-aspect-ratio</code>&rsquo; media features.)

  </ul>

  <div class=example>
   <p>For example, the &lsquo;<code class=css>color</code>&rsquo; media
    feature can form expressions without a value (&lsquo;<code
    class=css>(color)</code>&rsquo;), or with a value (&lsquo;<code
    class=css>(min-color: 1)</code>&rsquo;).</p>
  </div>

  <p class=note>This specification defines media features usable with visual
   and tactile devices. Similarly, media features can be defined for aural
   media types.

  <h3 id=width><span class=secno>4.1. </span>width</h3>

  <div class=media-feature><span class=label>Value:</span> &lt;length&gt;<br>
   <span class=label>Applies to:</span> visual and tactile media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>width</code>&rsquo; media feature describes
   the width of the targeted display area of the output device. For
   continuous media, this is the width of the viewport (as described by CSS2,
   section 9.1.1 <a href="#CSS21"
   rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>) including the size of a
   rendered scroll bar (if any). For paged media, this is the width of the
   page box (as described by CSS2, section 13.2 <a href="#CSS21"
   rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>).

  <p>A specified &lt;length> cannot be negative.

  <div class=example>
   <p>For example, this media query expresses that the style sheet is usable
    on printed output wider than 25cm:</p>

   <pre><code>&lt;link rel="stylesheet" media="print and (min-width: 25cm)" href="http://&hellip;" /></code></pre>
  </div>

  <div class=example>
   <p>This media query expresses that the style sheet is usable on devices
    with viewport (the part of the screen/paper where the document is
    rendered) widths between 400 and 700 pixels:</p>

   <pre><code>@media screen and (min-width: 400px) and (max-width: 700px) { &hellip; }</code></pre>
  </div>

  <div class=example>
   <p>This media query expresses that style sheet is usable on screen and
    handheld devices if the width of the viewport is greater than 20em.</p>

   <pre><code>@media handheld and (min-width: 20em),
  screen and (min-width: 20em) { &hellip; }</code></pre>

   <p>The &lsquo;<code class=css>em</code>&rsquo; value is relative to the
    initial value of ‘font-size’.</p>
  </div>

  <h3 id=height><span class=secno>4.2. </span>height</h3>

  <div class=media-feature><span class=label>Value:</span> &lt;length&gt;<br>
   <span class=label>Applies to:</span> visual and tactile media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>height</code>&rsquo; media feature describes
   the height of the targeted display area of the output device. For
   continuous media, this is the height of the viewport including the size of
   a rendered scroll bar (if any). For paged media, this is the height of the
   page box.

  <p>A specified &lt;length> cannot be negative.

  <h3 id=device-width><span class=secno>4.3. </span>device-width</h3>

  <div class=media-feature><span class=label>Value:</span> &lt;length&gt;<br>
   <span class=label>Applies to:</span> visual and tactile media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>device-width</code>&rsquo; media feature
   describes the width of the rendering surface of the output device. For
   continuous media, this is the width of the screen. For paged media, this
   is the width of the page sheet size.

  <p>A specified &lt;length> cannot be negative.

  <div class=example>
   <pre><code>@media screen and (device-width: 800px) { &hellip; }</code></pre>

   <p>In the example above, the style sheet will apply only to screens that
    currently displays exactly 800 horizontal pixels. The &lsquo;<code
    class=css>px</code>&rsquo; unit is of the logical kind, as described in
    the <a href="#units">Units</a> section.</p>
  </div>

  <h3 id=device-height><span class=secno>4.4. </span>device-height</h3>

  <div class=media-feature><span class=label>Value:</span> &lt;length&gt;<br>
   <span class=label>Applies to:</span> visual and tactile media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>device-height</code>&rsquo; media feature
   describes the height of the rendering surface of the output device. For
   continuous media, this is the height of the screen. For paged media, this
   is the height of the page sheet size.

  <p>A specified &lt;length> cannot be negative.

  <div class=example>
   <pre><code>&lt;link rel="stylesheet" media="screen and (device-height: 600px)" /&gt;</code></pre>

   <p>In the example above, the style sheet will apply only to screens that
    have exactly 600 vertical pixels. Note that the definition of the
    &lsquo;<code class=css>px</code>&rsquo; unit is the same as in other
    parts of CSS.</p>
  </div>

  <h3 id=orientation><span class=secno>4.5. </span>orientation</h3>

  <div class=media-feature><span class=label>Value:</span> portrait |
   landscape<br>
   <span class=label>Applies to:</span> bitmap media types<br>
   <span class=label>Accepts min/max prefixes:</span> no<br>
  </div>

  <p>The &lsquo;<code class=css>orientation</code>&rsquo; media feature is
   &lsquo;<code class=css>portrait</code>&rsquo; when the value of the
   &lsquo;<code class=css>height</code>&rsquo; media feature is greater than
   or equal to the value of the &lsquo;<code class=css>width</code>&rsquo;
   media feature. Otherwise &lsquo;<code class=css>orientation</code>&rsquo;
   is &lsquo;<code class=css>landscape</code>&rsquo;.

  <div class=example>
   <pre><code>@media all and (orientation:portrait) { &hellip; }
@media all and (orientation:landscape) { &hellip; }</code></pre>
  </div>

  <h3 id=aspect-ratio><span class=secno>4.6. </span>aspect-ratio</h3>

  <div class=media-feature><span class=label>Value:</span> &lt;ratio&gt;<br>
   <span class=label>Applies to:</span> bitmap media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>aspect-ratio</code>&rsquo; media feature is
   defined as the ratio of the value of the &lsquo;<code
   class=css>width</code>&rsquo; media feature to the value of the
   &lsquo;<code class=css>height</code>&rsquo; media feature.

  <h3 id=device-aspect-ratio><span class=secno>4.7.
   </span>device-aspect-ratio</h3>

  <div class=media-feature><span class=label>Value:</span> &lt;ratio&gt;<br>
   <span class=label>Applies to:</span> bitmap media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>device-aspect-ratio</code>&rsquo; media
   feature is defined as the ratio of the value of the &lsquo;<code
   class=css>device-width</code>&rsquo; media feature to the value of the
   &lsquo;<code class=css>device-height</code>&rsquo; media feature.

  <div class=example>
   <p>For example, if a screen device with square pixels has 1280 horizontal
    pixels and 720 vertical pixels (commonly referred to as "16:9"), the
    following Media Queries will all match the device:</p>

   <pre><code>@media screen and (device-aspect-ratio: 16/9) { &hellip; }
@media screen and (device-aspect-ratio: 32/18) { &hellip; }
@media screen and (device-aspect-ratio: 1280/720) { &hellip; }
@media screen and (device-aspect-ratio: 2560/1440) { &hellip; }</code></pre>
  </div>

  <h3 id=color><span class=secno>4.8. </span>color</h3>

  <div class=media-feature><span class=label>Value:</span>
   &lt;integer&gt;<br>
   <span class=label>Applies to:</span> visual media types<br>
   <span class=label>Accept min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>color</code>&rsquo; media feature describes
   the number of bits per color component of the output device. If the device
   is not a color device, the value is zero.

  <p>A specified &lt;integer> cannot be negative.

  <div class=example>
   <p>For example, these two media queries express that a style sheet applies
    to all color devices:</p>

   <pre><code>@media all and (color) { &hellip; }
@media all and (min-color: 1) { &hellip; }</code></pre>
  </div>

  <div class=example>
   <p>This media query expresses that a style sheet applies to color devices
    with 2 or more bits per color component:</p>

   <pre><code>@media all and (min-color: 2) { &hellip; }</code></pre>
  </div>

  <p>If different color components are represented by different number of
   bits, the smallest number is used.

  <div class=example>
   <p>For instance, if an 8-bit color system represents the red component
    with 3 bits, the green component with 3 bits and the blue component with
    2 bits, the &lsquo;<code class=css>color</code>&rsquo; media feature will
    have a value of 2.</p>
  </div>

  <p>In a device with indexed colors, the minimum number of bits per color
   component in the lookup table is used.

  <p class=note>The described functionality is only able to describe color
   capabilities at a superficial level. If further functionality is required,
   RFC2531 <a href="#RFC2531" rel=biblioentry>[RFC2531]<!--{{RFC2531}}--></a>
   provides more specific media features which may be supported at a later
   stage.

  <h3 id=color-index><span class=secno>4.9. </span>color-index</h3>

  <div class=media-feature><span class=label>Value:</span>
   &lt;integer&gt;<br>
   <span class=label>Applies to:</span> visual media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>color-index</code>&rsquo; media feature
   describes the number of entries in the color lookup table of the output
   device. If the device does not use a color lookup table, the value is
   zero.

  <p>A specified &lt;integer> cannot be negative.

  <div class=example>
   <p>For example, here are two ways to express that a style sheet applies to
    all color index devices:</p>

   <pre><code>@media all and (color-index) { &hellip; }
@media all and (min-color-index: 1) { &hellip; }</code></pre>
  </div>

  <div class=example>
   <p>This media query expresses that a style sheet applies to a color index
    device with 256 or more entries:</p>

   <pre><code>&lt;?xml-stylesheet media="all and (min-color-index: 256)"
  href="http://www.example.com/&hellip;" ?&gt;</code></pre>
  </div>

  <h3 id=monochrome><span class=secno>4.10. </span>monochrome</h3>

  <div class=media-feature><span class=label>Value:</span>
   &lt;integer&gt;<br>
   <span class=label>Applies to:</span> visual media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>monochrome</code>&rsquo; media feature
   describes the number of bits per pixel in a monochrome frame buffer. If
   the device is not a monochrome device, the output device value will be 0.

  <p>A specified &lt;integer> cannot be negative.

  <div class=example>
   <p>For example, here are two ways to express that a style sheet applies to
    all monochrome devices:</p>

   <pre><code>@media all and (monochrome) { &hellip; }
@media all and (min-monochrome: 1) { &hellip; }</code></pre>
  </div>

  <div class=example>
   <p>Express that a style sheet applies to monochrome devices with more than
    2 bits per pixels:</p>

   <pre><code>@media all and (min-monochrome: 2) { &hellip; }</code></pre>
  </div>

  <div class=example>
   <p>Express that there is one style sheet for color pages and another for
    monochrome:</p>

   <pre><code>&lt;link rel="stylesheet" media="print and (color)" href="http://&hellip;" /&gt;
&lt;link rel="stylesheet" media="print and (monochrome)" href="http://&hellip;" /&gt;</code></pre>
  </div>

  <h3 id=resolution><span class=secno>4.11. </span>resolution</h3>

  <div class=media-feature><span class=label>Value:</span>
   &lt;resolution&gt;<br>
   <span class=label>Applies to:</span> bitmap media types<br>
   <span class=label>Accepts min/max prefixes:</span> yes<br>
  </div>

  <p>The &lsquo;<code class=css>resolution</code>&rsquo; media feature
   describes the resolution of the output device, i.e. the density of the
   pixels. When querying devices with non-square pixels, in &lsquo;<code
   class=css>min-resolution</code>&rsquo; queries the least-dense dimension
   must be compared to the specified value and in &lsquo;<code
   class=css>max-resolution</code>&rsquo; queries the most-dense dimensions
   must be compared instead. A &lsquo;<code
   class=css>resolution</code>&rsquo; (without a "min-" or "max-" prefix)
   query never matches a device with non-square pixels.

  <p>For printers, this corresponds to the screening resolution (the
   resolution for printing dots of arbitrary color).

  <div class=example>
   <p>For example, this media query expresses that a style sheet is usable on
    devices with resolution greater than 300 dots per inch:</p>

   <pre><code>@media print and (min-resolution: 300dpi) { &hellip; }</code></pre>
  </div>

  <div class=example>
   <p>This media query expresses that a style sheet is usable on devices with
    resolution greater than 118 dots per centimeter:</p>

   <pre><code>@media print and (min-resolution: 118dpcm) { &hellip; }</code></pre>
  </div>

  <h3 id=scan><span class=secno>4.12. </span>scan</h3>

  <div class=media-feature><span class=label>Value:</span> progressive |
   interlace<br>
   <span class=label>Applies to:</span> "tv" media types<br>
   <span class=label>Accepts min/max prefixes:</span> no<br>
  </div>

  <p>The &lsquo;<code class=css>scan</code>&rsquo; media feature describes
   the scanning process of "tv" output devices.

  <div class=example>
   <p>For example, this media query expresses that a style sheet is usable on
    tv devices with progressive scanning:</p>

   <pre><code>@media tv and (scan: progressive) { &hellip; }</code></pre>
  </div>

  <h3 id=grid><span class=secno>4.13. </span>grid</h3>

  <div class=media-feature><span class=label>Value:</span>
   &lt;integer&gt;<br>
   <span class=label>Applies to:</span> visual and tactile media types<br>
   <span class=label>Accepts min/max prefixes:</span> no<br>
  </div>

  <p>The &lsquo;<code class=css>grid</code>&rsquo; media feature is used to
   query whether the output device is grid or bitmap. If the output device is
   grid-based (e.g., a "tty" terminal, or a phone display with only one fixed
   font), the value will be 1. Otherwise, the value will be 0.

  <p>Only 0 and 1 are valid values. (This includes -0.) Thus everything else
   creates a malformed media query.

  <div class=example>
   <p>Here are two examples:</p>

   <pre><code>@media handheld and (grid) and (max-width: 15em) { &hellip; }</code>
<code>@media handheld and (grid) and (max-device-height: 7em) { &hellip; }</code></pre>
  </div>

  <h2 id=values><span class=secno>5. </span>Values</h2>

  <p>This specification also introduces two new values.

  <p>The &lt;ratio> value is a positive (not zero or negative) &lt;integer>
   followed by optional whitespace, followed by a solidus (&lsquo;<code
   class=css>/</code>&rsquo;), followed by optional whitespace, followed by a
   positive &lt;integer>.

  <p>The &lt;resolution> value is a positive &lt;number> immediately followed
   by a unit identifier (&lsquo;<code class=css>dpi</code>&rsquo; or
   &lsquo;<code class=css>dpcm</code>&rsquo;).

  <p>Whitespace, &lt;integer>, &lt;number> and other values used by this
   specification are the same as in other parts of CSS, normatively defined
   by CSS 2.1. <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>

  <h2 id=units><span class=secno>6. </span>Units</h2>

  <p>The units used in media queries are the same as in other parts of CSS.
   For example, the pixel unit represents CSS pixels and not physical pixels.

  <p>Relative units in media queries are based on the initial value, which
   means that units are never based on results of declarations. For example,
   in HTML, the &lsquo;<code class=css>em</code>&rsquo; unit is relative to
   the initial value of &lsquo;<code class=property>font-size</code>&rsquo;.

  <h3 id=resolution0><span class=secno>6.1. </span>Resolution</h3>

  <p>The &lsquo;<code class=css>dpi</code>&rsquo; and &lsquo;<code
   class=css>dpcm</code>&rsquo; units describe the resolution of an output
   device, i.e., the density of device pixels. Resolution unit identifiers
   are:

  <dl>
   <dt>dpi

   <dd>dots per CSS &lsquo;<code class=css>inch</code>&rsquo;

   <dt>dpcm

   <dd>dots per CSS &lsquo;<code class=css>centimeter</code>&rsquo;
  </dl>

  <p>In this specification, these units are only used in the &lsquo;<code
   class=css>resolution</code>&rsquo; media feature.

  <h2 id=changes><span class=secno>7. </span>Changes</h2>

  <h3 id=changes-2022><span class=secno>7.1. </span>Changes Since the 05 April 2022
   Recommendation</h3>

  An earlier Proposed Correction was normatively incorporated into the Recommendation:
  <ul>
   <li id=c1>
    Former “Proposed Correction 1” in <a href="#error-handling">Section 3.1</a>:
    Clarify that the keywords ‘<code>not</code>’, ‘<code>and</code>’, ‘<code>only</code>’, and ‘<code>or</code>’ should not be treated as unknown media types,
    but as syntax errors when used in place of media types.

    <blockquote>
     <p>Unknown media types evaluate to
      false. Effectively, they are treated identically to known media types
      that do not match the media type of the device.
      <ins>However, an exception is made for media types ‘<code>not</code>’, ‘<code>and</code>’, ‘<code>only</code>’, and ‘<code>or</code>’.
      Even though they do match the IDENT production,
      they must not be treated as unknown media types,
      but rather trigger the malformed query clause.</ins></p>
	</blockquote>

    <p>
    The reasoning for this change can be found in <a href="https://lists.w3.org/Archives/Public/www-style/2013May/0783.html">the minutes of the 2013-05-30 CSS WG teleconference</a>
   and in the emails referenced therefrom.

    <p>
    <a href="https://github.com/web-platform-tests/wpt/commit/ea1821d4bd24ed1e859db03571cca8e783dbf957">Tests for this change</a> have been added to <abbr title="Web Platform Tests">WPT</abbr>.
      The results can be viewed at <a href="https://wpt.fyi/results/css/mediaqueries?q=mq-invalid-media-type-0">wpt.fyi</a>.
  </ul>

  <p>A Proposed Correction was introduced:
  <ul>
   <li><a href="#c2">Proposed Correction 2</a> in <a href="#error-handling">Section 3.1</a>:
    Require that ‘<code>layer</code>’ is also to not be treated as an unknown media type,
    but as a syntax errors when used in place of media types.
  </ul>

  <h3 id=changes-2012><span class=secno>7.2. </span>Changes Since the 19 June 2012
   Recommendation</h3>

  <p>Proposed Corrections were introduced:
  <ul>
   <li><a href="#c1">Proposed Correction 1</a> in <a href="#error-handling">Section 3.1</a>:
    Clarify that the keywords ‘<code>not</code>’, ‘<code>and</code>’, ‘<code>only</code>’, and ‘<code>or</code>’ should not be treated as unknown media types,
    but as syntax errors when used in place of media types.
  </ul>

  <p>A handful of editorial and markup corrections were also made:

  <ul>
   <li><a href="#media0">Section 2</a>: Dropped a redundant attribute in an example.
    <blockquote>
     <pre><code>&lt;link <del>rel="stylesheet" </del>media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css"&gt;</code></pre>
     <pre><code>&lt;link <del>rel="stylesheet" </del>media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" /&gt;</code></pre>
    </blockquote>

   <li><a href="#media0">Section 2</a>: Adjusted a sentence to make it easier for other specifications to extend this one.
    <blockquote>
     To avoid circular dependencies, <del>it is never</del><ins>unless another feature explicitly specifies that it affects the resolution of Media Queries, it is not</ins> necessary to apply the style sheet in order to evaluate expressions.
    </blockquote>

   <li><a href="#syntax">Section 3</a>: Used a more precise term to characterize the syntax of css,
    in a descriptive (rather than prescriptive) sentence.
    <blockquote>
     CSS style sheets are generally <del>case-insensitive</del>
     <a href="https://infra.spec.whatwg.org/#ascii-case-insensitive"><ins>ASCII case-insensitive</ins></a>,
     and this is also the case for media queries.
    </blockquote>
    The veracity of this claim is validated by a <a href="https://wpt.fyi/results/css/mediaqueries/mq-case-insensitive-001.html">test</a>.

   <li><a href="#grid">Section 4.13</a>: Corrected a syntax error in an example.
    <blockquote>
     <pre><code>@media handheld and (grid) and (<del>device-max-height</del><ins>max-device-height</ins>: 7em) { … }</code></pre>
    </blockquote>

   <li>Bibliographical references have been updated to point to the latest versions.

   <li>Various links throughout the specification were updated from http to https.
  </ul>

  <h3 id=changes-2010><span class=secno>7.3. </span>Changes Since the 27 July
   2010 Candidate Recommendation</h3>

  <p>The following changes were made to this specification since the <a
   href="https://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/">27 July
   2010 Candidate Recommendation</a>:

  <ul>
   <li><a href="#resolution">Section 4.11</a>: Clarified the meaning of
    resolution in the case of printers, for which the meaning of dots was
    ambiguous.
    <blockquote>
     <p><ins>For printers, this corresponds to the screening resolution (the
      resolution for printing dots of arbitrary color).</ins>
    </blockquote>

   <li><a href="#units">Section 6.1</a>: Made it explicit that the
    &lsquo;<code class=css>inch</code>&rsquo; and &lsquo;<code
    class=css>cm</code>&rsquo; mentioned are the CSS units, not the physical
    ones.
    <blockquote>
     <dl>
      <dt>dpi

      <dd>dots per <ins>CSS &lsquo;<code
       class=css>inch</code>&rsquo;</ins><del>inch</del>

      <dt>dpcm

      <dd>dots per <ins>CSS &lsquo;<code
       class=css>centimeter</code>&rsquo;</ins><del>cm</del>
     </dl>
    </blockquote>

   <li><a href="#width">Section 4.1</a>: Adjust mistaken non normative
    wording to match correct normative wording from <a href="#units">Section
    6</a>.
    <blockquote>
     <p>The &lsquo;<code class=css>em</code>&rsquo; value is relative to the
      <del>font size of the root element</del><ins>initial value of
      ‘font-size’.</ins>.
    </blockquote>

   <li><a href="#units">Section 6</a>: Clarify that units are never based on
    the results of declarations.
    <blockquote>
     <p>Relative units in media queries are based on the initial value<ins>,
      which means that units are never based on results of
      declarations</ins>. For example, in HTML, the &lsquo;<code
      class=css>em</code>&rsquo; unit is relative to the initial value of
      &lsquo;<code class=property>font-size</code>&rsquo;.
    </blockquote>
  </ul>

  <h2 class=no-num id=acknowledgments>Acknowledgments</h2>

  <p>This specification is the product of the W3C Working Group on Cascading
   Style Sheets.

  <p>Comments from Bj&ouml;rn H&ouml;hrmann, Christoph P&auml;per, Chris
   Lilley, Simon Pieters, Rijk van Geijtenbeek, Sigurd Lerstad, Arve
   Bersvendsen, Susan Lesch, Philipp Hoschka, Roger Gimson, Steven Pemberton,
   Simon Kissane, Melinda Grant, and L. David Baron improved this
   specification.

   <h2 class="no-num heading settled" id="privacy"><span class="content">Privacy Considerations</span><a class="self-link" href="#privacy"></a></h2>
   <p>No new privacy considerations have been reported on this specification.</p>
   <h2 class="no-num heading settled" id="security"><span class="content">Security Considerations</span><a class="self-link" href="#security"></a></h2>
   <p>No new security considerations have been reported on this specification.</p>

  <h2 class=no-num id=references>References</h2>

  <h3 class=no-num id=normative-references>Normative references</h3>
  <!--begin-normative-->
  <!-- Sorted by label -->

  <dl class=bibliography>
   <dt style="display: none"><!-- keeps the doc valid if the DL is empty -->
    <!---->

   <dt id=CSS21>[CSS21]

   <dd>Bert Bos; et al. <a
    href="http://www.w3.org/TR/2011/REC-CSS2-20110607"><cite>Cascading Style
    Sheets Level 2 Revision 1 (CSS&#160;2.1) Specification.</cite></a> 7 June
    2011. W3C Recommendation. URL: <a
    href="http://www.w3.org/TR/2011/REC-CSS2-20110607">http://www.w3.org/TR/2011/REC-CSS2-20110607</a>
    </dd>
   <!---->
  </dl>
  <!--end-normative-->

  <h3 class=no-num id=other-references>Other references</h3>
  <!--begin-informative-->
  <!-- Sorted by label -->

  <dl class=bibliography>
   <dt style="display: none"><!-- keeps the doc valid if the DL is empty -->
    <!---->

   <dt id=HTML401>[HTML401]

   <dd>Dave Raggett; Arnaud Le Hors; Ian Jacobs. <a
    href="https://www.w3.org/TR/2018/SPSD-html401-20180327/"><cite>HTML 4.01
    Specification.</cite></a> 24 December 1999, superseded 27 March 2018. W3C Recommendation. URL: <a
    href="https://www.w3.org/TR/2018/SPSD-html401-20180327/">https://www.w3.org/TR/2018/SPSD-html401-20180327/</a>
    </dd>
   <!---->

   <dt id="biblio-html">[HTML]

   <dd>Anne van Kesteren; et al. <a
    href="https://html.spec.whatwg.org/multipage/"><cite>HTML
    Standard</cite></a>. Living Standard. URL: <a
    href="https://html.spec.whatwg.org/multipage/">https://html.spec.whatwg.org/multipage/</a>
    </dd>
   <!---->

   <dt id=RFC2531>[RFC2531]

   <dd>G. Klyne; L. McIntyre. <a
    href="http://www.ietf.org/rfc/rfc2531.txt"><cite>Content Feature Schema
    for Internet Fax.</cite></a> March 1999. Internet RFC 2531. URL: <a
    href="http://www.ietf.org/rfc/rfc2531.txt">http://www.ietf.org/rfc/rfc2531.txt</a>
    </dd>
   <!---->

   <dt id=XMLSTYLE>[XMLSTYLE]

   <dd>James Clark; Simon Pieters; Henry S. Thompson <a
    href="http://www.w3.org/TR/2010/REC-xml-stylesheet-20101028/"><cite>Associating Style Sheets
    with XML documents 1.0 (Second Edition)</cite></a> 28 October 2010. W3C
    Recommendation. URL: <a
    href="http://www.w3.org/TR/2010/REC-xml-stylesheet-20101028/">http://www.w3.org/TR/2010/REC-xml-stylesheet-20101028/</a>
    </dd>
   <!---->
   <ins cite=#c2>
   <dt id="biblio-css-cascade-5">[CSS-CASCADE-5]
   <dd>
      Elika Etemad; Miriam Suzanne; Tab Atkins Jr..
      <a href="https://www.w3.org/TR/css-cascade-5/"><cite>CSS Cascading and Inheritance Level 5</cite></a>.
      13 January 2022. CR.
      URL: <a href="https://www.w3.org/TR/css-cascade-5/">https://www.w3.org/TR/css-cascade-5/</a>
   </dd>
   </ins>
  </dl>
  <!--end-informative-->

  <p role="navigation" id="back-to-top"><a href="#title"><abbr title="Back to top">↑</abbr></a></p>

<script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script>
